<template>
  <div>
    <!-- 面包屑部分 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col>
          <el-input style="width:400px" placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderDataList" stripe style="width: 100%" border>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="100px"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款" width="100px">
          <template v-slot="slotScope">
            <el-tag type="success" v-if="slotScope.row.order_pay==='1'" size="small">已付款</el-tag>
            <el-tag type="danger" v-else size="small">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="100px"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="160px">
          <template v-slot="soltScope">{{soltScope.row.create_time | dataFormat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="160px">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="adressBox"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="logisticsBox"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址的对话框 -->
    <el-dialog title="修改地址" :visible.sync="addressVisible" width="50%" @close="addressVisibleClose">
      <!-- 修改地址的表单 -->
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRule"
        label-width="100px"
      >
        <el-form-item label="省市/区" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="Citydata"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息的对话框 -->
    <el-dialog
      title="物流详情"
      :visible.sync="logisticsVisible"
      width="50%"
      @close="logisticsVisibleClose"
    >
      <!-- 时间线 -->
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(activity, index) in logisticsArr"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import Citydata from './citydata';
export default {
  data() {
    return {
      // 定义请求参数
      queryInfo: {
        query: '',
        //   当前页码
        pagenum: 1,
        //   每页显示条数
        pagesize: 10,
      },
      //   订单数据列表对象
      orderDataList: [],
      //   数据总条数
      total: 0,
      // 修改地址对话框的显示与隐藏
      addressVisible: false,
      // 绑定的表单对象
      addressForm: {
        address1: '',
        address2: '',
      },
      // 定义验证规则
      addressFormRules: {
        address1: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
      },
      // 省市联动的城市名数组
      Citydata,
      // 物流详情的对话框的显示与隐藏
      logisticsVisible: false,
      // 存储物流信息的数组
      logisticsArr: [],
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //  获取订单数据列表
    async getOrderList() {
      const data = await this.$http.get('orders', { params: this.queryInfo });
      //   console.log(data);
      if (!data) return this.$message.error('请求订单列表失败！');
      //   将数据赋值
      this.orderDataList = data.goods;
      this.total = data.total;
    },
    // pageSize 改变时会触发
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    // pagenum 改变时会触发
    handleCurrentChange(nawPage) {
      this.queryInfo.pagenum = nawPage;
      this.getOrderList();
    },
    // 修改地址按钮
    adressBox() {
      this.addressVisible = true;
    },
    // 关闭修改地址的对话框
    addressVisibleClose() {
      // 重置表单
      this.$refs.addressFormRule.resetFields();
      this.addressVisible = false;
    },
    // 物流对话框关闭的函数
    logisticsVisibleClose() {
      this.logisticsVisible = false;
    },
    // 物流详情的按钮
    async logisticsBox() {
      // 获取物流详细信息
      const data = await this.$http.get('/kuaidi/' + '1106975712662');
      if (!data) return this.$message.error('获取物流信息失败！');
      // console.log(data);
      this.logisticsArr = data;
      this.logisticsVisible = true;
    },
  },
};
</script>

<style lang="less" scoped>
// .el-input {
//   width: 400px;
// }
.el-cascader {
  width: 100%;
}
</style>
